using Gateway.IApplication.BaseInput;
using Gateway.IApplication.Department;
using Gateway.IApplication.Department.Input;
using Gateway.IQuery.Department;
using Gateway.IQuery.Department.Request;
using Gateway.IQuery.Department.Result;

namespace Gateway.UI.Api.Controllers;

/// <summary>
/// 部门服务
/// </summary>
public class DepartmentController : BaseController
{
    private readonly IDepartmentApp _departmentApp;
    private readonly IDepartmentQuery _departmentQuery;

    /// <summary>
    /// 
    /// </summary>
    /// <param name="departmentApp"></param>
    /// <param name="departmentQuery"></param>
    public DepartmentController(IDepartmentApp departmentApp, IDepartmentQuery departmentQuery)
    {
        _departmentApp = departmentApp;
        _departmentQuery = departmentQuery;
    }

    /// <summary>
    /// 创建部门
    /// </summary>
    /// <param name="input"></param>
    /// <returns>返回主键标识</returns>
    [HttpPost, Route("add")]
    public async Task<string> Add(CreateDepartmentInput input)
    {
        return await _departmentApp.Add(input);
    }

    /// <summary>
    /// 更新部门
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    [HttpPost, Route("update")]
    public async Task<bool> Update(UpdateDepartmentInput input)
    {
        return await _departmentApp.Update(input);
    }

    /// <summary>
    /// 删除部门
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    [HttpPost, Route("remove")]
    public async Task<bool> Remove(RemoveInput input)
    {
        return await _departmentApp.Remove(input.Id);
    }

    /// <summary>
    /// 删除部门 -批量
    /// </summary>
    /// <param name="ids"></param>
    /// <returns></returns>
    [HttpPost, Route("remove/batch")]
    public async Task<bool> BatchRemove(List<string> ids)
    {
        foreach (var item in ids)
        {
            await _departmentApp.Remove(item);
        }

        return true;
    }

    /// <summary>
    /// 获取部门详情
    /// </summary>
    /// <param name="id"></param>
    /// <returns></returns>
    [HttpGet, Route("detail/{id}")]
    public async Task<DepartmentDetailResult> GetDetail(string id)
    {
        return await _departmentQuery.GetDetail(id);
    }

    /// <summary>
    /// 获取树形部门
    /// </summary>
    /// <returns></returns>
    [HttpPost, Route("tree")]
    public async Task<List<DepartmentTreeResult>> GetTree(DepartmentTreeRequest request)
    {
        return await _departmentQuery.GetTree(request);
    }
}